/*
 * Copyright(C) 2022. Huawei Technologies Co.,Ltd. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef MODEL
#define MODEL
#include "MxBase/MxBase.h"
#include "MxBase/PostProcessBases/PostProcessDataType.h"
#include "MxBase/postprocess/include/ObjectPostProcessors/Yolov3PostProcess.h"
#include "opencv2/opencv.hpp"

struct V2Param
{
  uint32_t deviceId;
  std::string labelPath;
  std::string configPath;
  std::string modelPath;
  V2Param() {}
  V2Param(const uint32_t &deviceId, const std::string &labelPath, const std::string &configPath, const std::string &modelPath)
      : deviceId(deviceId), labelPath(labelPath), configPath(configPath), modelPath(modelPath) {}
};

class Yolo
{
public:
  explicit Yolo(const V2Param &v2Param);
  APP_ERROR Infer(MxBase::Image &inputImage, std::vector<MxBase::Tensor> &outputs);
  APP_ERROR PostProcess(std::vector<MxBase::Tensor> &yoloOutputs,
                        std::vector<MxBase::Rect> &cropRects,
                        int originalImageWidth,
                        int originalImageHeight);

protected:
  std::shared_ptr<MxBase::Model> modelDptr;
  std::shared_ptr<MxBase::Yolov3PostProcess> postProcessorDptr;

private:
  uint32_t deviceId = 0;
};

class WheNet
{
public:
  explicit WheNet(const V2Param &v2Param);
  APP_ERROR Infer(MxBase::Image &inputImage, std::vector<MxBase::Tensor> &outputs);
  void Softmax(std::vector<float> src, std::vector<float> &dst);
  float GetAngleFromTensor(MxBase::Tensor &tensor, const int shape_size);
  APP_ERROR PostProcess(std::vector<MxBase::Tensor> &outputs, MxBase::Rect cropConfig, std::map<std::string, double> &drawMap);
  void WheNetDraw(float yaw, float pitch, float roll, float tdx, float tdy, int size, std::map<std::string, double> &drawMap);

protected:
  std::shared_ptr<MxBase::Model> modelDptr;

private:
  uint32_t deviceId = 0;
};

#endif